/* Routines for coplanar waveguides.
 *
 * Copyright (c) 2001-2007 Roman Pahuta, Xaveer Leijtens
 *
 * This file is part of libMask.
 *
 * libMask is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * libMask is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with libMask.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "mask.h"

void cwg2(double l, double w, double g, double gnd) {
  sw3(l, w, g, gnd);
}
void cwg2_curve(double r, double a, double w, double g, double gnd) {
  cw3(r, a, w, g, gnd);
}
void cwg2_taper(double l, double w1, double w2, double g1, double g2,
    double gnd1, double gnd2) {
  taper3(l, w1, w2, g1, g2, gnd1, gnd2);
}

void sw3(double l, double w, double g, double gnd) 	
/* Draws a straight coplanar waveguide section	with length l, center 		*/
/* conductor width of w, gap of g and ground plane width of gnd			*/
{	
	double w_tot;
	w_tot=w+2*g+2*gnd;		/* Total area of coplanar structure	*/	
	movept(l,w_tot,4,7);		/* Moves pointer to top ground plane	*/
	rect(l,gnd,7,7);		/* Draws top ground plane		*/
	movept(l,w_tot,7,1);		/* Moves pointer to bottom ground plane	*/
	rect(l,gnd,1,1);		/* Draws bottom ground plane		*/
	movept(l,w_tot,1,4);		/* Moves pointer to center conductor	*/
	rect(l,w,4,6);		/* Draws center conductor		*/
}

void cw3(double r, double a, double w, double g, double gnd)	
/* Draws a curved coplanar waveguide section with a center conductor width 	*/
/* of w a gap wisth of g and ground plane width of gnd. For a curve to the 	*/
/* right, both a and radius r should be positive, for a turn to the left,	*/	
/* a and r should be negative							*/							
{		
	push_cp();
	offset(g+(w+gnd)/2);
	cw(r-(g+(w+gnd)/2),a,gnd);
	pop_cp();
	push_cp();
	offset(-(g+(w+gnd)/2));
	cw(r+(g+(w+gnd)/2),a,gnd);
	pop_cp();
	cw(r,a,w);
}

void taper3(double l,double w1,double w2,double g1,double g2,double gnd1,
 double gnd2)
/* Connects 2 coplanar waveguides of different dimensions. Can accomodate 	*/
/* different center conductor widths, different gaps and different ground 	*/
/* plane widths									*/
{
	double w1_tot;			/* Total width of structure initially	*/
	double w2_tot;			/* Total width of structure at end	*/
	double a;			/* Angle for ground planes		*/
	
	w1_tot=w1+2*g1+gnd1;
	w2_tot=w2+2*g2+gnd2;
	a=atan2((w2_tot-(w1_tot))/2,l);
	
	push_cp();
	movept(l,w1_tot,4,7);
	taper_angle(l,-a,gnd1,gnd2);
	pop_cp();
	push_cp();				
	movept(l,w1_tot,4,1);		
	taper_angle(l,a,gnd1,gnd2);		
	pop_cp();				
	push_cp();				
	movept(l,w1_tot,4,4);		
	taper(l,w1,w2);				
	pop_cp();				
	movept(l,w2_tot,4,6);		
}
